﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Mars.EnCor
{
    public class HashHelper
    {
        public static string MD5(string source)
        { 
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] bs = Encoding.Default.GetBytes(source);
            byte[] bd = md5.ComputeHash(bs);

            StringBuilder sb = new StringBuilder();
            foreach (byte b in bd)
            { 
                sb.Append(b.ToString("X2"));
            }
            return sb.ToString();
        }

        public static string MD5(Stream source)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] bd = md5.ComputeHash(source);

            StringBuilder sb = new StringBuilder();
            foreach (byte b in bd)
            {
                sb.Append(b.ToString("X2"));
            }
            return sb.ToString();
        }
    }
}
